package com.example.apple.printingroommanagementsystem;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by apple on 17/2/25.
 */

public class MyAdapter extends BaseAdapter {
    private ArrayList<MediaItem>mediaItems;
    private Context context;
    public MyAdapter(Context context,ArrayList<MediaItem>mediaItems) {
       this.context = context;
        this.mediaItems  =mediaItems;
    }

    @Override
    public int getCount() {
        return mediaItems.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if (convertView==null){
            convertView = View.inflate(context,R.layout.depart_ltem,null);
            viewHoder = new ViewHoder();
            viewHoder.id = (TextView) convertView.findViewById(R.id.item_id);
            viewHoder.name = (TextView) convertView.findViewById(R.id.item_name);
            viewHoder.department = (TextView) convertView.findViewById(R.id.item_department);
            convertView.setTag(viewHoder);
        }else {
            viewHoder = (ViewHoder) convertView.getTag();
        }
        MediaItem mediaItem = mediaItems.get(position);
        viewHoder.id.setText(mediaItem.getId());
        viewHoder.name.setText(mediaItem.getName());
        viewHoder.department.setText(mediaItem.getDepartment());
        Log.e("-->viewh",mediaItem.toString());
        return convertView;
    }

    private class ViewHoder {
        TextView id,name,department;
    }
}
